home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / oocs / cclienta.cls next >
Text File  |  1999-09-06  |  9KB  |  304 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "cClientActions"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. Option Explicit
  11.  
  12. '***********************************************************************
  13. '***********************************************************************
  14. '**                                                                   **
  15. '** cClientActions.cls - This class handles most of the winsock       **
  16. '**   Functions.
  17. '**                                                                   **
  18. '**                                                                   **
  19. '***********************************************************************
  20. '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  21. '^^ Author: gh0ul -@- August 99'                                      ^^
  22. '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  23. '***********************************************************************
  24.  
  25.  
  26.  
  27.  
  28. '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'
  29. '                                                                        '
  30. '  C L A S S  - P R O P E R T I E S                                      '
  31. '                                                                        '
  32. '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'
  33. Public SystemDir         As String
  34. Public WindowsDirectory  As String
  35. Public MemLoad           As String
  36. Public TotalPhys         As String
  37. Public AvailPhys         As String
  38. Public TotalPFile        As String
  39. Public AvailPFile        As String
  40. Public TotalVir          As String
  41. Public AvailVir          As String
  42.  
  43. Private m_sIPAddress     As String
  44. Private ChnkCnt          As Integer   ' Data Chunk Counter.
  45.  
  46. Private m_FilePath       As String
  47. Private m_NumFiles       As Long
  48. Public Packaged_SysInfo  As String
  49. Public CurDrive          As String
  50. Public IPAddress         As String
  51.  
  52. ' event to signify a connection has been made so that
  53. ' the client knows when to unload the IP Form.
  54. Public Event ConnMade()
  55.  
  56. ' this event lets the form know that a new chunk of data
  57. ' has been recieved and needs to be dealt with.
  58. Public Event IncomingDataChunk()
  59.  
  60. ' this event lets the form know when all the data chunks
  61. ' have been sent
  62. Public Event TransferDone()
  63.  
  64. Public Event DriveInputError()
  65.  
  66. Public Event SysInfoArrival()
  67.  
  68.  
  69. Public Property Get FilePath() As String
  70.    '
  71.    FilePath = m_FilePath
  72. End Property
  73.  
  74. Public Property Let FilePath(ByVal sNV As String)
  75.    m_FilePath = FilePath
  76. End Property
  77.  
  78.  
  79. Public Property Get NumFiles() As Long
  80.     NumFiles = m_NumFiles
  81. End Property
  82.  
  83. Public Property Let NumFiles(ByVal lNV As Long)
  84.     m_NumFiles = lNV
  85. End Property
  86.  
  87.  
  88. Private Sub Class_Initialize()
  89.      WindowsDirectory = "WIndows Directory"
  90.      MemLoad = "Memory Load:"
  91.      TotalPhys = "Total Physical Memory:"
  92.      AvailPhys = "Available Physical Memory:"
  93.      TotalPFile = "Pagefile Size:"
  94.      AvailPFile = "Available Pagefile Resources:"
  95.      TotalVir = "Total Virtual Memory:"
  96.      AvailVir = "Available Virtual Memory:"
  97. End Sub
  98.  
  99.  
  100.  
  101. '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'
  102. '                                                                        '
  103. '  C L A S S - M E T H O D S                                             '
  104. '                                                                        '
  105. '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'
  106.  
  107. Sub Connect(sIPAddress As String, Client As Winsock)
  108.     '
  109.     If sIPAddress = "" Then Exit Sub
  110.     
  111.     m_sIPAddress = sIPAddress
  112.     ' for public access
  113.     IPAddress = m_sIPAddress
  114.     'try to make a connection to the Server.
  115.     bReplied = False
  116.     Client.Connect sIPAddress, 333
  117.     
  118.     lTIme = 0
  119.     
  120.     While (Not bReplied) And (lTIme < 10000)
  121.         DoEvents
  122.         lTIme = lTIme + 1
  123.     Wend
  124.     
  125.     
  126.     If lTIme >= 10000 Then
  127.         'Didn't reply or timed out. close the connection
  128.         MsgBox "Unable to connect to remote server", vbCritical, "Connection Error"
  129.         
  130.         Client.Close
  131.         Exit Sub
  132.     End If
  133.     
  134.     ' connection made!
  135.     RaiseEvent ConnMade
  136. End Sub
  137.  
  138.  
  139. Sub DisConnect(Client As Winsock)
  140.     '
  141.      Client.Close
  142. End Sub
  143.  
  144.  
  145. Sub HandleIncomingData(sIncoming As String, Client As Winsock, Div As String)
  146.     '
  147.     Dim Command As String
  148.     Dim sIncomingData As String
  149.     
  150.     '--- when a command is sent the first seperater is a comma, the default.
  151.     '--- Therefore "sDivider" is not set.
  152.     
  153.     ' Extract the command from the Left
  154.     ' of the comma (default divider)
  155.     Command = EvalData(sIncoming, 1, Div)
  156.     ' extract the data being sent from the
  157.     ' right of the comma (default divider)
  158.     sIncomingData = EvalData(sIncoming, 2, Div)
  159.     ' decide what command has been issued
  160.     Select Case Command
  161.          Case "Accepted"
  162.              bReplied = True
  163.                           
  164.          Case "NumFiles"
  165.              m_NumFiles = CLng(sIncomingData)
  166.             
  167.          Case "Users_Data"
  168.              ' assign the new chunk to the FilePath property
  169.              ' to expose it
  170.              m_FilePath = sIncomingData
  171.              ' notify the form that a new chunk has been set
  172.              RaiseEvent IncomingDataChunk
  173.                      
  174.          Case "SysInfo"
  175.               ' assign the sent data to a public
  176.               ' property, so it will be exposed to the forms
  177.               ' and modules
  178.               Packaged_SysInfo = sIncomingData
  179.               ' trigger an event to do something
  180.               ' with newly recieved System Info
  181.               RaiseEvent SysInfoArrival
  182.                      
  183.          Case "Transfer_Done"
  184.              RaiseEvent TransferDone
  185.              
  186.     End Select
  187.     
  188. End Sub
  189.  
  190.  
  191. '======================================================================
  192. ' (EvalData Function)
  193. '
  194. '  Purpose - Extract data from a given string, to the right or left
  195. '            of a specified character.
  196. '
  197. '  Parameters:
  198. '     sIncoming - The String you want to extract data from.
  199. '     iRtLt     - Extract from the Left, 1.
  200. '                 Extract from the right, 2.
  201. '     sDivider  - The character that seperates the data in
  202. '                 the string. <default = ",">
  203. '  Returns:
  204. '     the data to the right or left of strDivider
  205. '======================================================================
  206.              
  207.  
  208. Function EvalData(sIncoming As String, iRtLt As Integer, _
  209.                   Optional sDivider As String) As String
  210.    Dim i As Integer
  211.    Dim TempStr As String
  212.    ' Storage for the current Divider
  213.    Dim sSplit As String
  214.    
  215.    ' the current character used to divide the data
  216.    If sDivider = "" Then
  217.       sSplit = ","
  218.    Else
  219.       sSplit = sDivider
  220.    End If
  221.    
  222.    ' getting the right or left?
  223.    Select Case iRtLt
  224.         
  225.       Case 1
  226.           ' remove the data to the Left of the Current Divider
  227.           For i = 0 To Len(sIncoming)
  228.             TempStr = Left(sIncoming, i)
  229.             
  230.             If Right(TempStr, 1) = sSplit Then
  231.               EvalData = Left(TempStr, Len(TempStr) - 1)
  232.               Exit Function
  233.             End If
  234.           Next
  235.           
  236.       Case 2
  237.           ' remove the data to the Right of the Current Divider
  238.           For i = 0 To Len(sIncoming)
  239.             TempStr = Right(sIncoming, i)
  240.             
  241.             If Left(TempStr, 1) = sSplit Then
  242.               EvalData = Right(TempStr, Len(TempStr) - 1)
  243.               Exit Function
  244.             End If
  245.           Next
  246.    End Select
  247.    
  248. End Function
  249.  
  250.  
  251.  
  252. ' --- Prompts the User for a string, sends it to the server,
  253. ' --- if not already being used
  254. Sub SendMsg(Client As Winsock)
  255.    Dim sMsg As String
  256.    
  257.    sMsg = InputBox("Enter a string to send")
  258.    On Error GoTo ErrH
  259.    If sMsg = "" Then
  260.      Exit Sub
  261.    End If
  262.    
  263.    If (Not SendData("Msg," & sMsg)) Then
  264.       Client.Close
  265.    End I